#pragma once
#include "Singleton.h"
#include "boost/asio.hpp"
#include <thread>
#include <vector>
#include <memory>

class AsioIOServicePool : public Singleton<AsioIOServicePool>
{
    friend class Singleton<AsioIOServicePool>;
    using IOService = boost::asio::io_context;
    using Work = boost::asio::io_context::work;
    using WorkPtr = std::unique_ptr<Work>;
public:
    AsioIOServicePool(const AsioIOServicePool&) = delete;
    AsioIOServicePool& operator=(const AsioIOServicePool&) = delete;




    ~AsioIOServicePool();
    boost::asio::io_context& GetIOService();
    void Stop();

private:
    AsioIOServicePool(int thread_num=1);
    
private:
    std::vector<IOService> _ioServices;
    std::vector<WorkPtr> _works;
    std::vector<std::thread> _threads;
    std::size_t _nextIOServiceIndex;//用于轮询
};
